﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMathLibrary.NumericalIntegration;

namespace SmartMathLibrary.Space.CoreTypes
{
    /// <summary>
    /// This class represents an integral.
    /// </summary>
    [Serializable]
    public class SpaceIntegral:ISpaceEntry
    {
        /// <summary>
        /// The lower border of the integral.
        /// </summary>
        [SpaceAttribute]
        private double a;

        /// <summary>
        /// The upper border of the integral.
        /// </summary>
        [SpaceAttribute]
        private double b;

        /// <summary>
        /// The function of the integral.
        /// </summary>
        private Polynomial function;

        /// <summary>
        /// Initializes a new instance of the <see cref="SpaceIntegral"/> class.
        /// </summary>
        /// <param name="a">The lower border of the integral.</param>
        /// <param name="b">The upper border of the integral.</param>
        /// <param name="function">The function of the integral.</param>
        public SpaceIntegral(double a, double b, Polynomial function)
        {
            this.a = a;
            this.b = b;
            this.function = function;
        }

        /// <summary>
        /// Gets or sets the lower border of the integral.
        /// </summary>
        /// <value>The lower border of the integral.</value>
        public double A
        {
            get { return this.a; }
            set { this.a = value; }
        }

        /// <summary>
        /// Gets or sets the upper border of the integral.
        /// </summary>
        /// <value>The upper border of the integral.</value>
        public double B
        {
            get { return this.b; }
            set { this.b = value; }
        }

        /// <summary>
        /// Gets or sets the function of the integral.
        /// </summary>
        /// <value>The function of the integral.</value>
        public Polynomial Function
        {
            get { return this.function; }
            set { this.function = value; }
        }

        /// <summary>
        /// Converts the current space type to a <see cref="SmartMathLibrary.NumericalIntegration.FinitelyDoubleIntegral"/>.
        /// </summary>
        /// <returns>The converted point.</returns>
        public FinitelyDoubleIntegral ToIntegral()
        {
            return new FinitelyDoubleIntegral(this.a,this.b,this.function.Copy());
        }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            return CloneFunctions.Clone(this);
        }

        /// <summary>
        /// Compares the current <see cref="ISpaceEntry"/> to the specified <see cref="ISpaceEntry"/>.
        /// </summary>
        /// <param name="entry">The specified entry to compare.</param>
        /// <returns>
        /// If the object instances are even, the method returns true otherwise, false.
        /// </returns>
        public bool Equals(ISpaceEntry entry)
        {
            if (entry is SpaceIntegral)
            {
                SpaceIntegral check = (SpaceIntegral) entry;

                return ((this.A == check.A) && (this.B == check.B) && (this.Function == check.function));
            }

            return false;
        }

        /// <summary>
        /// Compares the current <see cref="ISpaceEntry"/> to the specified <see cref="ISpaceEntry"/>.
        /// </summary>
        /// <param name="entry">The specified entry to compare.</param>
        /// <returns>
        /// If the specified object instance is lower than the current instance the method returns true otherwise,
        /// false.
        /// </returns>
        public bool LowerThan(ISpaceEntry entry)
        {
            return false;
        }

        /// <summary>
        /// Compares the current <see cref="ISpaceEntry"/> to the specified <see cref="ISpaceEntry"/>.
        /// </summary>
        /// <param name="entry">The specified entry to compare.</param>
        /// <returns>
        /// If the specified object instance is greater than the current instance the method returns true otherwise,
        /// false.
        /// </returns>
        public bool GreaterThan(ISpaceEntry entry)
        {
            return false;
        }
    }
}
